/* =================================================================================
File name:      BASIC_FUN.H   
===================================================================================*/

#ifndef __BASIC_FUN_H__
#define __BASIC_FUN_H__

/* Low Pass Filter Macro */
#define  MIN_FL           _IQ((1.0e-9))
#define  MAX_FL           _IQ(1.0) 
#define  LOW_FILTER(OUT,IN,FILT)          \
 (OUT) += _IQmpy((((FILT) < MAX_FL) ? (((FILT) < MIN_FL) ? MIN_FL : (FILT)): MAX_FL), ((IN) - (OUT)))

/* Limit Macro */
#define  LIMIT_SCOPE(REG,MAX,MIN,FLAG)    \
{                                         \
  if ((REG) >= (MAX))                     \
  {                                       \
    (REG) = (MAX);                        \
    (FLAG) = 1;                           \
  }                                       \
  else if ((REG) <= (MIN))                \
  {                                       \
  (REG) = (MIN);                          \
  (FLAG) = 2;                             \
  }                                       \
  else                                    \
  {                                       \
    (FLAG) = 0;                           \
  }                                       \
}

/* Bit Operation Macro */
#define  SET_BIT(BIT)         (1 << (BIT))
#define  CLR_BIT(BIT)         (~(1 << (BIT)))
#define  IS_BIT_SET(REG,BIT)  ((REG) & (1 << (BIT)))

//#define SET_BIT(REG, BIT)     ((REG) |= (BIT))

//#define CLEAR_BIT(REG, BIT)   ((REG) &= ~(BIT))

//#define READ_BIT(REG, BIT)    ((REG) & (BIT))

//#define MODIFY_REG(REG, CLEARMASK, SETMASK)  WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))

//#define POSITION_VAL(VAL)     (__CLZ(__RBIT(VAL)))

#define FALSE   0
#define TRUE    1

#ifndef PI
  #define PI 3.14159265358979
#endif

#endif // __BASIC_FUN_H__
